﻿package net.wangit.view.element.component;

import net.wangit.Row;
import net.wangit.context.ActionContext;
import net.wangit.support.AbstractElementWriter;
import net.wangit.view.element.ElementComponent;
import net.wangit.view.element.util.ElementUtil;
import net.wangit.view.util.Html;

public class IFrameElementWriter extends AbstractElementWriter {

	public IFrameElementWriter() {
	}

	protected void writeText(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		writeControl(ac, html, ec, row);
	}

	protected void writeTextWithValue(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		writeControl(ac, html, ec, row);
	}

	protected void writeControl(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		writeControlWithDisplay(ac, html, ec, row, false);
	}

	protected void writeReadOnlyControl(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		writeControl(ac, html, ec, row);
	}

	protected void writeDisabledControl(ActionContext actioncontext,
			StringBuffer stringbuffer, ElementComponent elementcomponent,
			Row row1) {
	}

	protected void writeHidden(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row) {
		writeControlWithDisplay(ac, html, ec, row, true);
	}

	private void writeControlWithDisplay(ActionContext ac, StringBuffer html,
			ElementComponent ec, Row row, boolean hidden) {
		html.append("<iframe");
		if (hidden) {
			html.append(" style=\"display:none\"");
		}
		Html.setAttribute(html, ElementUtil.resolveCustom(ac, ec, row));
		Html.setId(html, ElementUtil.getAlias(ec));
		Html.setCss(html, ec.getCss());
		Html.setSrc(html, ElementUtil.resolveLink(ac, ec, row));
		Html.setWidth(html, ec.getWidth());
		Html.setHeight(html, ec.getHeight());
		html.append("></iframe>");
	}
}
